package edu.westga.sketchit2009cs.tester;

import static org.junit.Assert.*;
import edu.westga.sketchit2009cs.players.*;
import org.junit.Before;
import org.junit.Test;

/**
 * Tests the PlayerHandler class, which is responsible
 * for handling the list of players.
 * @author RJ Hill
 *
 */
public class PlayerHandlerTester {
	
	private Player playerOne;
	private Player playerTwo;
	private Player playerThree;
	private Player playerFour;
	private PlayerHandler theHandler;
	
	@Before
	public void SetUp() {
		this.playerOne = new Player("Jimmy", "127.0.0.1", 0, true);
		this.playerTwo = new Player("Fandango", "192.168.0.1", 0, false);
		this.playerThree = new Player("Will Lloyd", "160.241.0.23", 0, false);
		this.playerFour = new Player("Will Lloyd", "160.241.0.24", 0, false);
		this.theHandler = new PlayerHandler();
	}
	
	@Test
	public void shouldHavePlayerJimmyWhenAddPlayerOne() {
		this.theHandler.addPlayer(this.playerOne);
		assertEquals(this.theHandler.getPlayer(0), this.playerOne);
	}

	@Test
	public void shouldHaveListSizeZeroWhenRemovePlayerOne() {
		this.theHandler.addPlayer(this.playerOne);
		this.theHandler.removePlayer(this.playerOne);
		assertEquals(this.theHandler.getPlayerCount(), 0);
	}
	
	@Test
	public void shouldHavePlayerFandangoWhenAddPlayerOneAndPlayerTwo() {
		this.theHandler.addPlayer(this.playerOne);
		this.theHandler.addPlayer(this.playerTwo);
		assertEquals(this.theHandler.getPlayer(1), this.playerTwo);
	}
	
	@Test
	public void shouldHavePlayerWillLloyd01WhenAddAllFourPlayers() {
		this.theHandler.addPlayer(this.playerOne);
		this.theHandler.addPlayer(this.playerTwo);
		this.theHandler.addPlayer(this.playerThree);
		this.theHandler.addPlayer(this.playerFour);
		assertEquals(this.theHandler.getPlayer(3).getName(), "Will Lloyd1");
	}
	
	@Test
	public void shouldBeFandangoDrawingWhenNextPlayerToDraw() {
		this.theHandler.addPlayer(this.playerOne);
		this.theHandler.addPlayer(this.playerTwo);
		this.theHandler.addPlayer(this.playerThree);
		this.theHandler.addPlayer(this.playerFour);
		this.theHandler.nextPlayerToDraw();
		assertEquals(this.theHandler.getPlayer(1).getDrawingPriveleges(), true);
	}

}
